package com.ruoyi.configuration.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.configuration.domain.MgTextConf;
import com.ruoyi.configuration.service.IMgTextConfService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文本设置Controller
 * 
 * @author ruoyi
 * @date 2024-01-17
 */
@RestController
@RequestMapping("/configuration/text")
public class MgTextConfController extends BaseController
{
    @Autowired
    private IMgTextConfService mgTextConfService;

    /**
     * 查询文本设置列表
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:list')")
    @GetMapping("/list")
    public TableDataInfo list(MgTextConf mgTextConf)
    {
        startPage();
        List<MgTextConf> list = mgTextConfService.selectMgTextConfList(mgTextConf);
        return getDataTable(list);
    }

    /**
     * 导出文本设置列表
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:export')")
    @Log(title = "文本设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MgTextConf mgTextConf)
    {
        List<MgTextConf> list = mgTextConfService.selectMgTextConfList(mgTextConf);
        ExcelUtil<MgTextConf> util = new ExcelUtil<MgTextConf>(MgTextConf.class);
        util.exportExcel(response, list, "文本设置数据");
    }

    /**
     * 获取文本设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mgTextConfService.selectMgTextConfById(id));
    }

    /**
     * 新增文本设置
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:add')")
    @Log(title = "文本设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MgTextConf mgTextConf)
    {
    	String content = mgTextConf.getContent();
		if (null == content || "".equals(content)) {
    		return AjaxResult.error("内容不能为空");
    	}
		
		String title = mgTextConf.getTitle();
		
		if (null == title || "".equals(title)) {
            return AjaxResult.error("标题不能为空");
        }
		
    	
        return toAjax(mgTextConfService.insertMgTextConf(mgTextConf));
    }

    /**
     * 修改文本设置
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:edit')")
    @Log(title = "文本设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MgTextConf mgTextConf)
    {
        return toAjax(mgTextConfService.updateMgTextConf(mgTextConf));
    }

    /**
     * 删除文本设置
     */
    @PreAuthorize("@ss.hasPermi('configuration:text:remove')")
    @Log(title = "文本设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mgTextConfService.deleteMgTextConfByIds(ids));
    }
}
